namespace MoreLinq
{
    using System;

    /// <summary>
    /// The exception that is thrown for a sequence that fails a condition.
    /// </summary>

    [Serializable]
    public partial class SequenceException : Exception
    {
        const string DefaultMessage = "Error in sequence.";

        /// <summary>
        /// Initializes a new instance of the <see cref="SequenceException"/> class.
        /// </summary>

        public SequenceException() :
            this(null) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="SequenceException"/> class
        /// with a given error message.
        /// </summary>
        /// <param name="message">A message that describes the error.</param>

        public SequenceException(string? message) :
            this(message, null) { }

        /// <summary>
        /// Initializes a new instance of the <see cref="SequenceException"/> class
        /// with a given error message and a reference to the inner exception
        /// that is the cause of the exception.
        /// </summary>
        /// <param name="message">A message that describes the error.</param>
        /// <param name="innerException">The exception that is the cause of the current exception.</param>

#pragma warning disable IDE0290 // Use primary constructor (needed due to deserialization constructor)
        public SequenceException(string? message, Exception? innerException) :
#pragma warning restore IDE0290 // Use primary constructor
            base(string.IsNullOrEmpty(message) ? DefaultMessage : message, innerException) { }
    }
}

#if !NET7_0_OR_GREATER

// BinaryFormatter serialization APIs are obsolete
// https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/7.0/binaryformatter-apis-produce-errors

namespace MoreLinq
{
    using System.Runtime.Serialization;

    partial class SequenceException
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SequenceException"/> class
        /// with serialized data.
        /// </summary>
        /// <param name="info">The object that holds the serialized object data.</param>
        /// <param name="context">The contextual information about the source or destination.</param>

        protected SequenceException(SerializationInfo info, StreamingContext context) :
            base(info, context) { }
    }
}

#endif // !NET8_0_OR_GREATER
